<template>
  <div>
    <el-form :model="form" label-width="auto" style="max-width: 1000px" :inline="true">
    <el-button type="danger" @click="PostBasiAdd()">+ 新增</el-button>
    <el-button type="danger">保存</el-button>
    <el-button type="danger">撤销</el-button>
    <el-button type="danger">删除</el-button>
      </el-form>
      <br>
      <hr>
      <br>
      <h3>基本信息</h3>
      <br>
      <hr>
      <el-form :model="form" label-width="auto" style="max-width: 1000px"  :inline="true">
        <br>
    <el-form-item label="耳号">
      <el-input v-model="form.auricle" style="width: 250px;" placeholder="请输入"/>
    </el-form-item>
    <el-form-item label="品种">
      <el-select v-model="form.sheepbreedId" placeholder="请选择" style="width: 250px;">
        <el-option v-for="item in SheepBeedData" :label="item.sheepbreedName" :value="item.sheepbreedId" />
      </el-select>
    </el-form-item>
    <el-form-item label="电子耳号">
      <el-input v-model="form.corpuscleAuricle" style="width: 250px;" placeholder="请输入" />
    </el-form-item>
    <el-form-item label="基因等级">
      <el-select v-model="form.geneLV" placeholder="请选择" style="width: 250px;">
        <el-option label="后备级" :value=1 />
        <el-option label="核心级" :value=2 />
        <el-option label="生产级" :value=3 />
        <el-option label="未定级" :value=4 />
      </el-select>
    </el-form-item>
    <el-form-item label="羊只性别">
      <el-radio-group v-model="form.SheepTypeId" style="width: 400px;">
        <el-radio :value=1>公</el-radio>
        <el-radio :value=2>母</el-radio>
      </el-radio-group>
    </el-form-item>
      </el-form>
      <br>
      <br>
      <br>
      <h3>出生信息</h3>
      <br>
      <hr>
      <br>
      <el-form :model="form" label-width="auto" style="max-width: 1200px"  :inline="true">
        <br>
        <el-form-item label="父亲耳号">
      <el-select v-model="form.dadBreedingSheepArchiveId" placeholder="请选择" style="width: 250px;">
        <el-option v-for="item in EarData.filter(x=>x.sheepTypeId==1)" :label="item.auricle" :value="item.breedingSheepArchiveId" />
      </el-select>
    </el-form-item>
    <el-form-item label="母亲耳号">
      <el-select v-model="form.momBreedingSheepArchiveId" placeholder="请选择" style="width: 250px;">
        <el-option v-for="item in EarData.filter(x=>x.sheepTypeId==2)" :label="item.auricle" :value="item.breedingSheepArchiveId" />
      </el-select>
    </el-form-item>
    <el-form-item label="出生日期">
       <el-date-picker
        v-model="form.birthDate"
        type="date"
        placeholder="Pick a Date"
        format="YYYY-MM-DD"
        style="width: 250px;"
      />
    </el-form-item>
    <el-form-item label="入场日期">
       <el-date-picker
        v-model="form.admissionDate"
        type="date"
        placeholder="Pick a Date"
        format="YYYY-MM-DD"
        style="width: 250px;"
      />
    </el-form-item>

    <el-form-item label="出生场地">
      <el-input v-model="form.birthAdd" style="width: 250px;" placeholder="请输入" />
    </el-form-item>
    <el-form-item label="出生重（公斤）">
      <el-input v-model="form.birthWeight" style="width: 250px;" placeholder="请输入" />
    </el-form-item>
    <el-form-item label="备注">
      <el-input v-model="form.remark" type="textarea"  style="width: 800px;height: 80px;" placeholder="请输入"/>
    </el-form-item>
      </el-form>
  </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ElMessage } from 'element-plus';
import { reactive ,onMounted,ref} from 'vue';
onMounted(()=>{
  GetEarNum();
  SheepBeedSelest();
})
const form = reactive({
  "auricle": "",
  "sheepbreedId": '',
  "corpuscleAuricle": "",
  "geneLV": '',
  "SheepTypeId": '',
  "breedingSheepArchiveId": '',
  "dadBreedingSheepArchiveId":'',
  "momBreedingSheepArchiveId":'',
  "birthDate": "",
  "admissionDate": "",
  "birthAdd": "",
  "birthWeight": "",
  "remark": ""
})
//获取耳号
const EarData=ref([])
function GetEarNum()
{
  axios.post("http://localhost:5012/api/SheepFile/BasicInformationList",{})
  .then(res=>{
    console.log(res.data)
    EarData.value=res.data.data
  })
}
//基本信息出生信息新增
function PostBasiAdd()
{
  axios.post("http://localhost:5012/api/SheepFile/SheepFileAdd",{
    auricle: form.auricle,
  sheepbreedId:form.sheepbreedId,
  corpuscleAuricle:form.corpuscleAuricle ,
  geneLV:form.geneLV,
  isSex: form.isSex,
  breedingSheepArchiveId: 0,
  dadBreedingSheepArchiveId: form.dadBreedingSheepArchiveId,
  momBreedingSheepArchiveId:form.momBreedingSheepArchiveId,
  birthDate:form.birthDate,
  admissionDate:form. admissionDate,
  birthAdd:form. birthAdd,
  birthWeight: form.birthWeight,
  remark: form.remark
  })
  .then(res=>{
    console.log(res)
    if(res.data.code==0)
  {
    ElMessage.success("新增成功");
  }
  else
  {
    ElMessage.error("新增成功");
    return;
  }
  })
}
//品种下拉框
const SheepBeedData=ref([])
function SheepBeedSelest()
{
  axios.post("http://localhost:5012/api/SheepFile/SheepBeedList",{})
  .then(res=>{
    SheepBeedData.value=res.data.data
  })
}
</script>

<style scoped>

</style>